package com.four.reimbursemanage.service.impl;

import com.four.reimbursemanage.common.bean.Page;
import com.four.reimbursemanage.dao.CondolenceApplyMapper;
import com.four.reimbursemanage.entity.CondolenceApply;
import com.four.reimbursemanage.entity.Dailyapply;
import com.four.reimbursemanage.entity.Payapply;
import com.four.reimbursemanage.service.CondolenceApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CondolenceApplyServiceImpl implements CondolenceApplyService {
   @Autowired
   private CondolenceApplyMapper condolenceApplyMapper;
    @Override
    public Page<CondolenceApply> getOnrePage(int pageNum, int pageSize, String applyDepartment, String payee, Integer state) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<CondolenceApply> list=condolenceApplyMapper.getall(start,pageSize, applyDepartment, payee, state);
        //获取总条目数
        int total=condolenceApplyMapper.countCondolenceApply(applyDepartment, payee, state);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<CondolenceApply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    @Override
    public Page<CondolenceApply> getOnrePageUser(int pageNum, int pageSize, String applyDepartment, String payee, Integer state, String number) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<CondolenceApply> list=condolenceApplyMapper.getUser(start,pageSize, applyDepartment, payee, state, number);
        //获取总条目数
        int total=condolenceApplyMapper.countCondolenceApplyUser(applyDepartment, payee, state, number);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<CondolenceApply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    @Override
    public boolean insertComdolenceapply(CondolenceApply condolenceApply) {
        if (condolenceApply == null){
            return false;
        }
        return condolenceApplyMapper.insertComdolenceapply(condolenceApply)>0;
    }

    @Override
    public boolean updateCondolenceApply(CondolenceApply condolenceApply) {
        if (condolenceApply == null){
            return false;
        }
        return condolenceApplyMapper.updateCondolenceApply(condolenceApply)>0;
    }

    /*撤销*/
    @Override
    public boolean updateC(CondolenceApply condolenceApply) {
        if (condolenceApply == null) {
            return false;
        }
        condolenceApply.setState(3);
        return condolenceApplyMapper.updateStateById(condolenceApply)>0;
    }
}
